#include <iostream>
#include <stack>
#include <string>
bool isValidBracketSequence(const std::string& sequence) {
    std::stack<char> bracketsStack;
    for (char bracket : sequence) {
        if (bracket == '(' || bracket == '[' || bracket == '{') {
            bracketsStack.push(bracket);
        }
        else if (bracket == ')' || bracket == ']' || bracket == '}') {
            if (bracketsStack.empty()) {
                return false;
            }
            char topBracket = bracketsStack.top();
            bracketsStack.pop(); 
            if ((bracket == ')' && topBracket != '(')
                || (bracket == ']' && topBracket != '[')
                || (bracket == '}' && topBracket != '{')) {
                return false;
            }
        }
    }
    return bracketsStack.empty();
}
int main() {
    std::string bracketSequence;
    std::cout << "Введите скобочную последовательность: ";
    std::cin >> bracketSequence;
    bool isValid = isValidBracketSequence(bracketSequence);
    if (isValid) {
        std::cout << "True" << std::endl;
    } else {
        std::cout << "False" << std::endl;
    }
    return 0;
}
